﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Divisi.aspx.vb" Inherits="bisaska.Divisi" %>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeadContent" runat="server">
<script language="javascript">
    function ClientValidate(source, arguments) {
        var resp = 0;

        $.ajax({
            url: "Divisi.aspx/IsExist",
            data: '{ "kodeDivisi": "' + arguments.Value + '"}',
            type: "POST",
            async: false,
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {
                resp = result.d;
            },
            error: function (e) {
                alert(e);
            }
        });

        if (resp == "1") {
            arguments.IsValid = false;
        } else {
            arguments.IsValid = true;
        }

        
    }
    function OnSucceeded(result, userContext, methodName) {
        $get('Label1').innerHTML = result;
    }

    function OnFailed(error, userContext, methodName) {
        $get('Label1').innerHTML = "An error occured.";
    }
</script> 
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <div class="title">
    <span>.::</span>
    <span><b>Master Divisi</b></span>
	<em>::.</em>
	<em><%= DateTime.Now.ToString("dd MMMM yyyy")%></em>
	<div style="clear:both;"></div>
</div>
<form id="FormDivisi" runat="server" method="post">
<asp:ScriptManager ID="DivisiScriptManager" runat="server" EnablePartialRendering="true" EnablePageMethods="true"/>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<asp:GridView 
    ID="DivisiGridView" runat="server" 
    AllowPaging="True" 
    AllowSorting="True" 
    AutoGenerateColumns="False" 
    DataKeyNames="id_divisi" 
    DataSourceID="T_MST_DIV_Source" 
    CellPadding="4" 
    GridLines="None" 
    AlternatingRowStyle-CssClass="odd"
    CssClass="table-data">
      <Columns>
        <asp:BoundField DataField="id_divisi" HeaderText="ID" ItemStyle-Width="60px" InsertVisible="False" ReadOnly="True" SortExpression="id_divisi" />
        <asp:BoundField DataField="kode_divisi" HeaderText="Kode Divisi" ItemStyle-Width="80px" SortExpression="kode_divisi" />
        <asp:BoundField DataField="deskripsi" HeaderText="Deskripsi" SortExpression="deskripsi" />
        <asp:BoundField DataField="kode_satker" HeaderText="Kode Satker" ItemStyle-Width="80px" SortExpression="kode_satker" />
        <asp:BoundField DataField="is_active" HeaderText="Status" ItemStyle-Width="70px" ReadOnly="True" SortExpression="is_active" />
        <asp:BoundField DataField="tgl_update" HeaderText="Tanggal Update" ItemStyle-Width="140px" SortExpression="tgl_update" />
        <asp:ButtonField CommandName="CopyCommand" Text="Copy" ItemStyle-Width="30px" />
        <asp:ButtonField CommandName="EditCommand" Text="Edit" ItemStyle-Width="30px" />
        <asp:TemplateField ItemStyle-Width="30px">
           <ItemTemplate>
             <asp:LinkButton ToolTip="delete" ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Hapus data ?');" />
           </ItemTemplate>
        </asp:TemplateField>
       </Columns>
</asp:GridView>
                  
<div class="paging">
  <em><asp:Button ID="AddButton" runat="server" Text="Add New" CausesValidation="False" CssClass="button" /></em><div style="clear:both;"></div>
</div>     
<table runat="server" id="DivisiTableForm" cellpadding="0" cellspacing="2" border="0" class="table-form">
  <tr>
    <th style="width:80px;">ID</th>
    <td><asp:TextBox ID="IDDivisi" runat="server" ReadOnly="true" Columns="5"></asp:TextBox></td>
  </tr>
  <tr>
    <th style="width:80px;">Kode Divisi</th>
    <td>
      <asp:TextBox ID="KodeDivisi" runat="server" CssClass="textbox" Columns="12" MaxLength="12"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="KodeDivisi" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
        <asp:CustomValidator id="KodeDivisiValidator"
                ControlToValidate="KodeDivisi"
                ClientValidationFunction="ClientValidate"
                ErrorMessage="Data sudah ada !!"
                runat="server" />
    </td>
  </tr>
  <tr>
    <th>Satker</th>
    <td><asp:DropDownList ID="Satker" runat="server" DataSourceID="T_MST_Satker_Source" 
            DataTextField="kode_satker" DataValueField="kode_satker"></asp:DropDownList></td>
  </tr>
  <tr>
    <th valign="top">Deskripsi</th>
    <td>
      <asp:TextBox ID="Descripsi" runat="server" Rows="3" Columns="60" TextMode="MultiLine"  MaxLength="150" />
      <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Descripsi" ErrorMessage="*"></asp:RequiredFieldValidator>
    </td>
  </tr>
  <tr>
    <th>Status</th>
    <td>
      <asp:DropDownList ID="Status" runat="server">
        <asp:ListItem Value="0">Aktif</asp:ListItem>
        <asp:ListItem Value="1">Pasif</asp:ListItem>
      </asp:DropDownList>
     </td>
   </tr>
   <tr>
     <th></th>
     <td>
       <asp:Button ID="SaveButton" runat="server" Text="Save" CssClass="button"></asp:Button>
       <asp:Button ID="CancelButton" runat="server" Text="Cancel" CssClass="button"  CausesValidation="False"></asp:Button>
      </td>
   </tr>
</table>
<asp:SqlDataSource ID="T_MST_DIV_Source" runat="server" 
            ConnectionString="<%$ ConnectionStrings:bisaska %>" 
            SelectCommand="select id_divisi,kode_divisi,deskripsi,b.kode_satker,is_active = case a.is_active when 0 then 'Aktif' else 'Pasif' end,a.tgl_update  from T_MST_DIVISI a join T_MST_SATKER b on a.id_satker = b.id_satker "
            
        DeleteCommand="DELETE FROM [T_MST_DIVISI] WHERE [id_divisi] = @id_divisi">
            <DeleteParameters>
                <asp:Parameter Name="id_divisi" Type="Int64" />
            </DeleteParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="T_MST_Satker_Source" runat="server" 
            ConnectionString="<%$ ConnectionStrings:bisaska %>" 
            
        SelectCommand="SELECT [id_satker], [kode_satker], [nama_satker] FROM [T_MST_SATKER]">
</asp:SqlDataSource>    
</ContentTemplate>
</asp:UpdatePanel>    
</form>
</asp:Content>